package com.jxd.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jxd.dao.TravelInfoMapper;
import com.jxd.model.TravelInfo;
import com.jxd.service.ITravelInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.HashMap;
import java.util.Map;

@Service
public class TravelInfoServiceImpl
        extends ServiceImpl<TravelInfoMapper, TravelInfo> implements ITravelInfoService {

    @Autowired
    private TravelInfoMapper travelInfoMapper;

    @Override
    public Map<String, Object> getAllTravelInfoList(Map<String, String> queryMap) {
        String page = queryMap.get("page");
        String limit = queryMap.get("limit");
        String departureTime = queryMap.get("departureTime");
        String arrivalTime = queryMap.get("arrivalTime");
        int empno = Integer.parseInt(queryMap.get("empno"));

        Map<String, Object> map = new HashMap<>(4);
        if (page != null && limit != null) {
            IPage<TravelInfo> pages = new Page<>(Integer.parseInt(page), Integer.parseInt(limit));
            IPage<TravelInfo> pageResult = travelInfoMapper.getAllTravelInfoList(pages, departureTime, arrivalTime, empno);
            map.put("count", pageResult.getTotal());
            map.put("data", pageResult.getRecords());
            map.put("code", 0);
            return map;
        } else {
            map.put("data", (Object) null);
            map.put("code", "500");
            map.put("count", "参数不符");
            map.put("count", (Object) null);
            return map;
        }
    }
}
